# coding: utf-8
from sqlalchemy import Column, DateTime, ForeignKey, Integer, LargeBinary, String
from sqlalchemy.schema import FetchedValue
from sqlalchemy.orm import relationship
from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()



class InformationCode(db.Model):
    __tablename__ = 'information_codes'

    codeID = db.Column(db.String(30, 'utf8_general_ci'), primary_key=True, info='节点主键')
    codeName = db.Column(db.String(255, 'utf8_general_ci'), nullable=False, info='节点名称')
    parentCodeID = db.Column(db.String(30, 'utf8_general_ci'), nullable=False, index=True, server_default=db.FetchedValue(), info='父节点ID（0表示是第一个节点）')
    createTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')



class InformationInfo(db.Model):
    __tablename__ = 'information_info'

    informationID = db.Column(db.String(30), primary_key=True, info='资料主键')
    title = db.Column(db.String(255, 'utf8_general_ci'), nullable=False, info='标题')
    text = db.Column(db.String, info='资料内容')
    parentCodeID = db.Column(db.String(30, 'utf8_general_ci'), nullable=False, server_default=db.FetchedValue(), info='父节点')
    createTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')



class UserCollect(db.Model):
    __tablename__ = 'user_collect'

    collectID = db.Column(db.String(30, 'utf8_general_ci'), primary_key=True, info='收藏主键')
    parentID = db.Column(db.String(30, 'utf8_general_ci'), info='文件的父节点ID')
    userID = db.Column(db.String(30, 'utf8_general_ci'), nullable=False, info='用户ID')
    informationID = db.Column(db.ForeignKey('information_info.informationID', ondelete='CASCADE', onupdate='CASCADE'), index=True, info='资料ID')
    title = db.Column(db.String(255, 'utf8_general_ci'), nullable=False, info='收藏标题')
    text = db.Column(db.String, info='收藏内容')
    IsDeleted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='0 --没有删除  1--删除')
    type = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='收藏类型：\\r\\n0-普通收藏\\r\\n1-笔记收藏 2-笔记文件夹 3-收藏文件夹')
    createTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')

    information_info = db.relationship('InformationInfo', primaryjoin='UserCollect.informationID == InformationInfo.informationID', backref='user_collects')



class UserInfo(db.Model):
    __tablename__ = 'user_info'

    userID = db.Column(db.String(30, 'utf8_general_ci'), primary_key=True, info='用户主键')
    userName = db.Column(db.String(255), info='用户名')
    mail = db.Column(db.String(255, 'utf8_general_ci'), nullable=False, info='邮箱')
    password = db.Column(db.String(255, 'utf8_general_ci'), nullable=False, info='密码')
    otherInfo = db.Column(db.String(400), info='其他信息（json格式数据）')
    userType = db.Column(db.Integer, info='用户类型')
    createTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')
